<template>
  <div class="card-title">
    <div class="title">{{ title }}</div>
    <div class="sub-title">{{ subTitle || '' }}
    </div>
  </div>
</template>
<script setup lang="tsx">
import { onMounted, ref } from 'vue';

const props = defineProps({
  text: {
    type: String,
    default: '',
  },
});

const title = ref('');
const subTitle = ref('');

onMounted(() => {
  const text = props.text
    .replace('（', '(')
    .replace('）', ')')
    .match(/\(([^)]+)\)/);

  const textArr = props.text.split('/');
  if (text) {
    // eslint-disable-next-line prefer-destructuring
    subTitle.value = text[1] || '';
    title.value = props.text
      .replace('（', '(')
      .replace('）', ')')
      .replace(`(${subTitle.value})`, '');
  } else if (textArr.length >= 2) {
    // eslint-disable-next-line prefer-destructuring
    subTitle.value = textArr[1];
    // eslint-disable-next-line prefer-destructuring
    title.value = textArr[0];
  } else {
    title.value = props.text;
  }
});
</script>
<style lang="less" scoped>
.card-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;

  .title {
    font-size: 12px;
    font-weight: bold;
    text-wrap: nowrap;
  }

  .sub-title {
    font-size: 10px;
    height: 14px;
  }
}
</style>
